<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui" class="no-js">

<ui:composition template="startTemplate.xhtml">

	<ui:define name="title">
		<h:outputText value="#{i18n.timeSheet}" />
	</ui:define>
	
	<ui:define name="content">
	
	<!-- **************************************** TimeSheet table **************************************** -->
	
		<div class="span32">
			<h:form id="timeSheetForm" prependId="false">	
				<p:growl id="timeSheetGrowl" />
					
				<p:dataTable id="dataTableAllTimeSheet" value="#{listBean.listTimeSheet}" var="t">  			    
				    <f:facet name="header">
				    	<h:outputText value="#{i18n.listTimeSheetLabel}" />			    	
				    </f:facet>
				    
				    <p:column style="width:2%">  
			        	<p:commandLink id="timeSheetLink" ajax="true"
			        		update=":detailTimeSheetForm:dataTableAllTimeSheetDate">		            	
			            	<h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" /> 						 
							<f:setPropertyActionListener target="#{timeSheetBean.timeSheetView}" value="#{t}" /> 									          
					    </p:commandLink>   
			        </p:column>	
			        		      				     
				    <p:column headerText="#{i18n.lastNameLabel}">  
			            <h:outputText value="#{t.person.lastName} #{t.person.firstName}" />  
			        </p:column>
			        
			        <p:column headerText="#{i18n.applicationLabel}">			        	         
					   	<h:outputText value="#{t.application.name}" /> 					    
			        </p:column>	
			        	
			        <p:column headerText="#{i18n.moduleLabel}">			        				        	            	
			           	<h:outputText value="#{t.module.name}" />			            
			        </p:column>				        
			          
			        <f:facet name="footer">
				    	<p:commandButton id="showAddTimeSheet" value="#{i18n.addTimeSheetLabel}" icon="ui-icon-plus"
							type="button" onclick="newTimeSheetDlg.show()" />    
				    </f:facet>   
				</p:dataTable>  			
			</h:form>
		</div>
		
	<!-- **************************************** Dialog new timeSheet **************************************** -->
	
	    <h:form id="createTimeSheetForm">			     					      
		    <p:dialog id="newTimeSheetDialog" header="#{i18n.newTimeSheetLabel}" widgetVar="newTimeSheetDlg" 
		    	dynamic="true" showEffect="clip" hideEffect="scale">					        
		        <h:panelGrid id="newTimeSheetPanel" columns="1" styleClass="panel">					
						<p:selectOneMenu value="#{timeSheetBean.timeSheetNew.person}" 
							id="timeSheetPerson" required="true" requiredMessage="#{i18n.requiredPerson}" 
							filter="true" filterMatchMode="startsWith"
							converter="#{personConverterBean}" validator="#{personValidator.validate}"> 								
							<f:passThroughAttribute name="required" value="true" />
							<!-- App and/or Mod must be selected 
								 Validator is a person parameter; if no app or mod is selected, nothing is sent to controller -->
							<f:validator validatorId="newTimeSheetValidator" />
							<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
				            <f:selectItems value="#{listBean.listPerson}" var="p" itemLabel="#{p.lastName} #{p.firstName}" itemValue="#{p}" />			           	            	
				        </p:selectOneMenu>
				        
				        <p:selectOneMenu value="#{timeSheetBean.timeSheetNew.application}" 
							id="timeSheetApplication" filter="true" filterMatchMode="startsWith"
							converter="#{applicationConverterBean}" validator="#{applicationValidator.validate}"> 							
							<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
				            <f:selectItems value="#{listBean.listApplication}" var="a" itemLabel="#{a.name}" itemValue="#{a}" />			           	            	
				        </p:selectOneMenu>
				        
				        <p:selectOneMenu value="#{timeSheetBean.timeSheetNew.module}"
							id="timeSheetModule" filter="true" filterMatchMode="startsWith"
							converter="#{moduleConverterBean}" validator="#{moduleValidator.validate}"> 							
							<f:selectItem itemLabel="Select One" itemValue="Select One" />							            	            
				            <f:selectItems value="#{listBean.listModule}" var="m" itemLabel="#{m.name}" itemValue="#{m}" />			           	            	
				        </p:selectOneMenu>
				        										
						<f:facet name="footer">
				            <h:panelGroup style="display:block; text-align:center">
				                <p:commandButton id="createTimeSheetFormSubmit" action="#{timeSheetBean.create}" value="#{i18n.submit}" 
				                	update=":timeSheetForm:timeSheetGrowl, :timeSheetForm:dataTableAllTimeSheet,
				                	:createTimeSheetForm:newTimeSheetDialog" oncomplete="newTimeSheetDlg.hide()" />
				            </h:panelGroup>
				        </f:facet>				        	        			
				</h:panelGrid>		        
		    </p:dialog>			
		</h:form>	
		
	<!-- **************************************** Details timeSheetDate (table) **************************************** -->
		
		<div class="span66">			
			<h:form id="detailTimeSheetForm" prependId="false">
				<p:dataTable id="dataTableAllTimeSheetDate" value="#{timeSheetBean.timeSheetView.listTimeSheetDate}" 
					var="d">  			    
				    <f:facet name="header">
				    	<h:outputText value="#{timeSheetBean.timeSheetView.person.lastName} 
				    						 #{timeSheetBean.timeSheetView.person.firstName}
				    						 #{timeSheetBean.timeSheetView.application.name} 
				    						 #{timeSheetBean.timeSheetView.module.name}" />			    	
				    </f:facet>
				    <p:column style="width:2%">  
			            <p:rowToggler />			            		  
			        </p:column>  
				    <p:column headerText="#{i18n.dateLabel}" sortBy="#{d.date}">  
			            <h:outputText value="#{d.date}">
			            	<f:convertDateTime pattern="dd/MM/yyyy" />
			            </h:outputText>  
			        </p:column>
			        <p:column headerText="#{i18n.hourLabel}"> 		            
					    <h:outputText value="#{d.hour}" /> 
			        </p:column>		
			        
			        <p:rowExpansion>  
			            <p:panel header="#{i18n.doneLabel}">
							<h:outputText value="#{d.done}" />
						</p:panel>	  		
			        </p:rowExpansion>
			        
			        <f:facet name="footer">
				    	<p:commandButton id="showAddTimeSheetDate" value="#{i18n.addTimeSheetDateLabel}" icon="ui-icon-plus"
							update=":newTimeSheetDateForm:newTimeSheetDateDialog" oncomplete="newTimeSheetDateDlg.show()">
							<f:setPropertyActionListener target="#{timeSheetBean.timeSheetDateNew.timeSheet}" 
								value="#{timeSheetBean.timeSheetView}" /> 
						</p:commandButton>
				    </f:facet>   
				</p:dataTable>
			</h:form>
		</div>
		
	<!-- **************************************** Dialog new timeSheetDate **************************************** -->
		
		<h:form id="newTimeSheetDateForm">						        
		    <p:dialog id="newTimeSheetDateDialog" header="#{i18n.newTimeSheetDateLabel}" widgetVar="newTimeSheetDateDlg" 
		    	dynamic="true" showEffect="clip" hideEffect="scale">	
				<h:panelGrid id="newtimeSheetDatePanel" columns="2" styleClass="panel">
										
					<h:outputLabel id="timeSheetDateLabel" for="timeSheetDate"
						value="#{i18n.dateLabel}" />
					<p:calendar id="timeSheetDate" value="#{timeSheetBean.timeSheetDateNew.date}" 
						pattern="dd/MM/yyyy" mode="popup" size="19" required="true" requiredMessage="#{i18n.requiredDate}" >					
						<f:convertDateTime pattern="dd/MM/yyyy" />
						<f:passThroughAttribute name="required" value="true" />					
					</p:calendar>					
					
					<h:outputLabel id="timeSheetHourLabel" for="timeSheetHour"
						value="#{i18n.hourLabel}" />
					<h:inputText id="timeSheetHour" value="#{timeSheetBean.timeSheetDateNew.hour}" 
						required="true" requiredMessage="#{i18n.requiredHour}" >
						<f:passThroughAttribute name="required" value="true" />
						<f:convertNumber minFractionDigits="2" />
					</h:inputText>
												
					<h:outputLabel id="timeSheetDoneLabel" for="timeSheetDone"
						value="#{i18n.commentsLabel}" />
					<p:inputTextarea id="timeSheetDone" value="#{timeSheetBean.timeSheetDateNew.done}" 
						rows="3" cols="19" required="true" requiredMessage="#{i18n.requiredDone}" >
						<f:passThroughAttribute name="required" value="true" />
					</p:inputTextarea>
						
					<f:facet name="footer">
			            <h:panelGroup style="display:block; text-align:center">
			                <p:commandButton id="newtimeSheetDateFormSubmit" action="#{timeSheetBean.createDate}" value="#{i18n.submit}"
			                	update=":timeSheetForm:timeSheetGrowl, :timeSheetForm:dataTableAllTimeSheet,
			                	:detailTimeSheetForm:dataTableAllTimeSheetDate"
			                	oncomplete="newTimeSheetDateDlg.hide()" />
			            </h:panelGroup>
			        </f:facet>	
			        			
				</h:panelGrid>
			</p:dialog>
		</h:form>	 
	</ui:define>	
</ui:composition>
</html>